import React from "react";
import "../css/InputBox.css";
import eventEmitter from "./event";
export default class InputBox extends React.Component{
    constructor(props){
        super(props);
    }


    render(){
        return(
            <div className="input_container">
                <input type="text" ref="input"/>
                <button onClick={()=>{
                    console.log(this.refs.input);
                    let value = this.refs.input.value;
                    if(value.length === 0 ){
                        alert("添加不能为空!")
                        return;
                    }
                    var date =new Date();
                    var dataStr = `${date.getFullYear()}年${date.getMonth()+1}月${date.getDate()}日`
                    var message = {
                        content:value,
                        date:dataStr
                    }

                    //将要传递数据的组件发布自定义事件
                    eventEmitter.emit("sendMessageTooBoard",message)

                }}>提交</button>
            </div>
        )
    }
}